


/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：02/09/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/  
package com.application.yfstandard.dao;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.hibernate.Session;

import com.application.yfstandard.entity.YfStandard;
import com.application.yfstandard.struts.form.YfStandardForm;
import com.manager.commons.dao.HibernateGenericDao;
import com.manager.commons.page.PageBean;
 /**
 * 
 * Description:YfStandardDAO<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 02/09/2012 
 * 
 */
public class YfStandardDAO extends HibernateGenericDao<YfStandard>
{
    private static final Logger logger = Logger.getLogger(YfStandardDAO.class);

	private YfStandard yfStandard;

	public YfStandard getYfStandard() {
		return this.yfStandard;
	}

	public void setYfStandard(YfStandard yfStandard) {
		this.yfStandard = yfStandard;
	}

	public Integer getAllCountYfStandard(YfStandardForm yfStandardForm){
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT COUNT(0) FROM yf_standard t left join usertable u on t.operateid = u.id WHERE 1=1 ");
                sql = getStringBuffer(yfStandardForm,sql,args);
		return super.getCount(sql.toString(),args.toArray());
	}
        
	public void deleteYfStandards(YfStandardForm yfStandardForm){    	
    		String hql = " delete from YfStandard where id in  ( '" + yfStandardForm.getIds() + "')";
		Session session = this.getSession();
		try
		{
			session.createQuery(hql).executeUpdate();
		}
		catch(RuntimeException re)
		{
		        logger.error("deleteYfStandards failed");	
			throw re;
		}
		finally
		{
			if (session != null)
			{
				releaseSession(session);
			}
		}
       }

	public List searchYfStandard(YfStandardForm yfStandardForm,PageBean pageBean){  
	    List args = new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT * FROM yf_standard t left join usertable u on t.operateid = u.id WHERE 1=1 ");
		sql = getStringBuffer(yfStandardForm,sql,args);
		sql.append(" order by t.CREATE_DATE desc");
		return getPageInfo(pageBean,sql.toString(),args);
	}

	/**
	 * 查询条件的封装 
	 * @param departmentForm 
	 * @return
	 */
	private StringBuffer getStringBuffer(YfStandardForm yfStandardForm,StringBuffer buf, List args){
		/* 需要加入查询条件时封装
		*/
		
           				if(StringUtils.isNotBlank(yfStandardForm.getFileName())){
		    buf.append(" and t.FILE_NAME like ? ");
			args.add("%" + yfStandardForm.getFileName().trim() + "%");
		}
                				                
				if(null != yfStandardForm.getFileType() && yfStandardForm.getFileType().longValue() != 0){
	     	buf.append(" and t.FILE_TYPE = ? ");
			args.add(yfStandardForm.getFileType());
		}
				if(null != yfStandardForm.getBussType()){
			     	buf.append(" and t.BUSS_TYPE = ? ");
					args.add(yfStandardForm.getBussType());
				}           
		
                				                
				if(StringUtils.isNotBlank(yfStandardForm.getOperateid())){
	     	buf.append(" and u.rname like ? ");
	     	args.add("%" + yfStandardForm.getOperateid().trim() + "%");
		}
		                if(StringUtils.isNotBlank(yfStandardForm.getId())){
		                	buf.append(" and t.id = ? ");
							args.add(yfStandardForm.getId());
		                }
		
                				return buf;
	}
	
}
	